<html>

	<head>
		<meta charset="UTF-8">
		<title>计量回路列表</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<link rel="stylesheet" href="../../layui/css/layui.css" />
		<link rel="stylesheet" href="../../layui/css/font/iconfont.css" />
		<link rel="stylesheet" href="../../css/bass.css" />
		<style type="text/css">
			.dtree-menubar .layui-btn-group .layui-btn-sm {
				width: 50px;
				height: 30px;
				background-color: #009688;
				color: #fff;
				border: none;
				border-radius: 2px;
				margin-right: 10px !important;
			}
			
			.dtree-menubar .layui-btn-group .layui-btn-sm i {
				font-size: 16px !important;
			}
		</style>
	</head>

	<body>
		<div class="body">
			<header class="layui-nav" id="headerTop"></header>
			<div class="left_muen" id="left_menu"></div>
			<div class="content_body">
				<p class="content_title">站点管理 &nbsp;&nbsp;>&nbsp;&nbsp;计量回路列表</p>
				<div class="content_seach">
					<div class="content_seach">
						<div class="layui-form">
							<div class="layui-inline">
								<label class="layui-form-label">计量回路名称</label>
								<div class="layui-input-inline">
									<input type="text" class="layui-input" name="circuitName" id="test31" placeholder="请输入计量回路名称">
								</div>
							</div>
							<!--<div class="layui-form-item">-->
							<div class="layui-inline">
								<label class="layui-form-label">供应站点名称</label>
								<div class="layui-input-block">
									<select name="siteId" lay-search="" id="siteName">
										<option value="">请选择站名</option>
									</select>
								</div>
							</div>
							<div class="layui-inline">
								<label class="layui-form-label">输出站点名称</label>
								<div class="layui-input-block">
									<select name="endsiteId" lay-search="" id="endsiteName">
										<option value="">请选择站名</option>
									</select>
								</div>
							</div>
							<!--</div>-->
							<div class="layui-btn layui-btn-warm search layui-btn-sm" id="search" lay-submit="" lay-filter="search">
								<i class="layui-icon">&#xe615;</i>查询
							</div>
						</div>
					</div>
				</div>
				<div class="content_table" style="margin-top: 20px;">
					<script type="text/html" id="toolbarDemo">
						<div class="layui-btn-container">
							<button class="layui-btn layui-btn-sm" lay-event="addCheckData"><i class="layui-icon">&#xe654;</i> 添加</button>
							<button class="layui-btn layui-btn-sm" lay-event="delCheckData"><i class="layui-icon">&#xe640;</i>删除</button>
						</div>
					</script>
					<div class="tabTable">
						<table id="demo" lay-filter="table" lay-data="{id:'idTest'}"></table>
						<div class="layui-table-page fr">
							<div id="layui-table-page1"></div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<script type="text/html" id="barContractUpdate">
			<a class="layui-btn layui-btn-xs" lay-event="edit"><i class="layui-icon">&#xe642;</i>编辑</a>
			<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon">&#xe640;</i>删除</a>
		</script>
		<script src="../../js/common/jquery-1.11.3.min.js"></script>
		<script src="../../layui/layui.js"></script>
		<script src="../../js/common/navList.js"></script>
		<script src="../../js/common/ajax.js"></script>
		<script>
			layui.use(['table', 'form', 'layer'], function() {
				var table = layui.table;
				var form = layui.form;
				// 	请求供应站点数据
				ajaxGet({
					url: 'site/getListNoPage',
					successFull: function(res) {
						console.log(res);
						if(res.list.length != 0) {
							$.each(res.list, function(i, item) {
								$("#siteName").append('<option value="' + item.id + '">' + item.siteName + '</option>');
								$("#endsiteName").append('<option value="' + item.id + '">' + item.siteName + '</option>');
							});
						}
						layui.form.render('select'); //重新渲染select
					},
					errCallBack: function(res) {

					}
				});
				ajaxTable({
					idNode: '#demo',
					url: 'meteringcircuit/getList',
					dataCols: [{
							type: 'checkbox',
							templet: function(res) {
								console.log(111)
							}
						},
						{
							field: 'circuitName',
							title: '回路名称',
							align: 'center'
						},
						{
							field: 'startSiteName',
							title: '供应站点',
							align: 'center'
						},
						{
							field: 'endSiteName',
							title: '输出站点',
							align: 'center'
						},
						{
							field: 'dataDelayed',
							title: '数据延迟',
							align: 'center'
						},
						{
							field: 'circuitDesc',
							title: '回路描述',
							align: 'center'
						},
						{
							field: 'circuitTitle',
							title: '回路简称',
							align: 'center',
							templet: '#maTypeTemplet',
						},
						{
							field: 'autoReadFrequency',
							title: '自动读取频率',
							align: 'center'
						},
						{
							field: 'unitHeatVal',
							title: '单位热值',
							align: 'center',
							templet: function(res) {
								console.log(res)
								if(res.unitHeatVal == 1) {
									res.unitHeatVal = '标方'
								} else if(res.unitHeatVal == 2) {
									res.unitHeatVal = '吉焦'
								} else if(res.unitHeatVal == 3) {
									res.unitHeatVal = '吨'
								}
								return res.unitHeatVal;
							},
						},
						{
							field: 'deviceCode',
							title: '计量设备',
							align: 'center'
						},
						{
							field: 'right',
							title: '操作',
							width: 170,
							toolbar: "#barContractUpdate"
						}
					],
					successFull: function(res, curr, count, table) {
						console.log(res)
						table.on('toolbar(table)', function(obj) {
							var checkStatus = table.checkStatus(obj.config.id);
							var data = checkStatus.data;
							if(obj.event == 'addCheckData') {
								window.location.href = './backTouterAdd.html?pos=1&childPos=1'
							} else if(obj.event == 'delCheckData') {
								//                        console.log(111)
								var data = checkStatus.data;
								if(data.length <= 0) {
									layer.msg('请勾选要删除的站点', {
										icon: 6
									});
								} else {
									layer.confirm('确定删除吗？', function(index) {
										console.log(data);
										var ids = [];
										$.each(data, function(i, item) {
											ids.push(item.id)
										});
										$.ajax({
											url: baseUrl + "meteringcircuit/batchDel",
											type: "POST",
											data: {
												ids: ids
											},
											dataType: "json",
											success: function(data) {
												if(data.code == 200) {
													layer.close(index);
													layer.msg("删除成功", {
														icon: 6
													});
													updata()
												} else {
													layer.msg("删除失败", {
														icon: 5
													});
												}
											}
										});
									});
								}
							}
						})
					}
				});

				//        条件查询
				form.on('submit(search)', function(data) {
					var urlParme,circuitName,siteId,endsiteId;
					circuitName = "&circuitName=" + data.field.circuitName;
					siteId = "&siteId="+data.field.siteId;
					endsiteId = "&endSiteId="+data.field.endsiteId;
					if(data.field.circuitName == ""){
						circuitName = "";
					};
					if(data.field.siteId == ""){
						siteId = "";
					};
					if(data.field.endsiteId == ""){
						endsiteId = "";
					};
					urlParme = circuitName+siteId+endsiteId;
					ajaxTable({
						idNode: '#demo',
						url: 'meteringcircuit/getList',
						urlParme: urlParme,
						dataCols: [{
								fixed: true,
								checkbox: true
							},
							{
								field: 'circuitName',
								checkbox: true,
								title: '回路名称',
								align: 'center'
							},
							{
								field: 'startSiteName',
								title: '供应站点',
								align: 'center'
							},
							{
								field: 'endSiteName',
								title: '输出站点',
								align: 'center'
							},
							{
								field: 'dataDelayed',
								title: '数据延迟',
								align: 'center'
							},
							{
								field: 'circuitDesc',
								title: '回路描述',
								align: 'center'
							},
							{
								field: 'circuitTitle',
								title: '回路简称',
								align: 'center',
								templet: '#maTypeTemplet',
							},
							{
								field: 'autoReadFrequency',
								title: '自动读取频率',
								align: 'center'
							},
							{
								field: 'unitHeatVal',
								title: '单位热值',
								align: 'center',
								templet: function(res) {
									console.log(res)
									if(res.unitHeatVal == 1) {
										res.unitHeatVal = '标方'
									} else if(res.unitHeatVal == 2) {
										res.unitHeatVal = '吉焦'
									} else if(res.unitHeatVal == 3) {
										res.unitHeatVal = '吨'
									}
									return res.unitHeatVal;
								},
							},
							{
								field: 'deviceCode',
								title: '计量设备',
								align: 'center'
							},
							{
								field: 'right',
								title: '操作',
								width: 170,
								toolbar: "#barContractUpdate"
							}
						],
						successFull: function(res, curr, count, table) {

						}
					});
				});
				table.on('tool(table)', function(obj) {
					var data = obj.data;
					if(obj.event === 'detail') {
						layer.msg('ID：' + data.id + ' 的查看操作');
					} else if(obj.event === 'del') {
						layer.confirm('确定删除吗？', function(index) {
							console.log(data);
							$.ajax({
								url: baseUrl + "meteringcircuit/del",
								type: "POST",
								data: {
									"id": data.id
								},
								dataType: "json",
								success: function(data) {
									if(data.code == 200) {
										obj.del();
										layer.close(index);
										layer.msg("删除成功", {
											icon: 6
										});
										updata();
									} else {
										layer.msg("删除失败", {
											icon: 5
										});
									}
								}
							});
						});
					} else if(obj.event === 'edit') {
						layer.confirm('确定修改吗？', function(index) {
							window.location.href = './backTouterEdit.html?pos=1&childPos=1&id=' + data.id;
						});
					}
				});
			});

			function updata() {
				ajaxTable({
					idNode: '#demo',
					url: 'meteringcircuit/getList',
					dataCols: [{
							fixed: true,
							checkbox: true
						},
						{
							field: 'circuitName',
							title: '回路名称',
							align: 'center'
						},
						{
							field: 'startSiteName',
							title: '供应站点',
							align: 'center'
						},
						{
							field: 'endSiteName',
							title: '输出站点',
							align: 'center'
						},
						{
							field: 'dataDelayed',
							title: '数据延迟',
							align: 'center'
						},
						{
							field: 'circuitDesc',
							title: '回路描述',
							align: 'center'
						},
						{
							field: 'circuitTitle',
							title: '回路简称',
							align: 'center',
							templet: '#maTypeTemplet',
						},
						{
							field: 'autoReadFrequency',
							title: '自动读取频率',
							align: 'center'
						},
						{
							field: 'unitHeatVal',
							title: '单位热值',
							align: 'center',
							templet: function(res) {
								console.log(res)
								if(res.unitHeatVal == 1) {
									res.unitHeatVal = '标方'
								} else if(res.unitHeatVal == 2) {
									res.unitHeatVal = '吉焦'
								} else if(res.unitHeatVal == 3) {
									res.unitHeatVal = '吨'
								}
								return res.unitHeatVal;
							},
						},
						{
							field: 'deviceCode',
							title: '计量设备',
							align: 'center'
						},
						{
							field: 'right',
							title: '操作',
							width: 170,
							toolbar: "#barContractUpdate"
						}
					]
				})
			}
		</script>
	</body>

</html>